﻿@model XSTDZ.ERP.Application.DataContracts.PieceDto

@{
    ViewBag.Title = " - 编辑计件";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<h2>编辑计件</h2>
<div class="wp100">
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    <tr>
        <td class="title"> 计件人员@*@Html.LabelFor(model => model.WorkGroupID)*@</td>
        <td> @Html.TextBoxFor(model => model.UserName, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.WorkGroupID)
          @Html.HiddenFor(model => model.Id)
          @Html.HiddenFor(model => model.WorkGroupID)
           @Html.HiddenFor(model => model.BillState)
        </td>

        <td class="title">@Html.LabelFor(model => model.ProductProcedureID)</td>
        <td>  @Html.TextBoxFor(model => model.ProductProcedureName, new { @class = "text" })
              @Html.HiddenFor(model => model.ProductProcedureID)
            @Html.ValidationMessageFor(model => model.ProductProcedureID)
             <a href="javascript:void(0);" onclick="javascript:selectPPId();" >选择</a>
         </td>
  </tr>
       <tr>
        <td class="title"> @Html.LabelFor(model => model.PieceCount)</td>
        <td> @Html.TextBoxFor(model => model.PieceCount, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.PieceCount)
        </td>

        <td class="title">@Html.LabelFor(model => model.SubmitDate)</td>
        <td>  @Html.TextBoxFor(model => model.SubmitDate, new { @class = "text" })
        <input type="hidden" value="@Model.SubmitDate" id="SubmitDateVal" name="SubmitDateVal" />
            @Html.ValidationMessageFor(model => model.SubmitDate)
         </td>
  </tr>



    <tr>
        <td  colspan="4">
              <p class="divBtn">
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="hidden" id="hidHttpPostState" name="hidHttpPostState" value="@ViewBag.PostState" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
             <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
    </table>
}
</div>

<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>

<script type="text/javascript">
    $(document).ready(function () {
        //工作组
        getSelectWorkGroupUser("UserName");
        //时间
        $("#SubmitDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left'
        });
        var productInDateVal = $("#SubmitDateVal").val();
        $("#SubmitDate").ligerGetDateEditorManager().setValue(productInDateVal);


        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
    });
    //选择 工序
    function selectPPId() {
        var returnValue = window.showModalDialog('../ProductProcedure/Select', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=800px;dialogHeight=400px");
        if (returnValue != null && returnValue != undefined) {
            $("#ProductProcedureName").val(returnValue[0]);
            $("#ProductProcedureID").val(returnValue[1]);
                }
//        $("#ProductProcedureName").val("测试工序(要修改)");
//        $("#ProductProcedureID").val("E1C2BEFA-0E38-CA67-5C9B-08D07AB7F296");
    }



    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {

            if (!isConfirm) {
                btnText = $("#submitBtn").val();
                $("#submitBtn").val("").val("正在处理中...");
            }
            else {
                btnText = $("#btnSubmit").val();
                $("#btnSubmit").val("").val("正在处理中...");
            }
            $.ajax({ type: "POST", url: "/Piece/AddAndConfirm?isConfirm=" + isConfirm, data: $('form').serialize(), // 要提交的表单
                success: function (msg) {
                    if (msg == "9") {
                        ajaxSubmitSuccess();
                        $.ligerDialog.success('操作成功!');
                        initligerGrid();

                    }
                    else if (msg == "0") {
                        $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                    }
                    else if (msg == "-1") {
                        $.ligerDialog.success('入库单明细数据不完整,操作失败!');
                    }
                    else {
                        $.ligerDialog.success('操作失败!');
                    }
                    if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                }
            });

        }
    } 

  </script>